package com.ywm.vod.dynamic_proxy.handle;

import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
//代理类
@AllArgsConstructor
@NoArgsConstructor
public class MyShellHandle implements InvocationHandler {
    private Object target=null;
    //动态代理，，目标活动是固定的
    public void setTarget(Object target) {
        this.target = target;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        Object res=null;
        //参数一：表示要执行对象的方法
        //参数二：方法执行时的参数
        //返回值：方法执行的返回值

        for (Object arg : args) {
            System.out.println("=============="+arg+"=============");
            res=method.invoke(target,args);
            if (res != null) {
                float price = (Float) res;
                res= (price + 25)*(int)arg;
            }
        }
        //增加后的价格
        return res;
    }
}
